const Mock = require('mockjs'); // 假数据

module.exports = function (app) {
    const prefix = '/api/task/';
    const taskList = Mock.mock({ // 生成任务列表
        'list|20': [{
            'id': '@increment(100)',
            'taskNumber': '@id',
            'taskName': '@csentence(5)',
            'founder': '@cname',
            'foundTime': '@datetime',
            'personLiable': '@cname',
            'completeTime': null,
            'taskPriority': '一般',
            'taskStatus': '待接受',
            'restart': 1,
            'overdue': 0,
            'pause': false
        }],
        'rowcount': 200
    });
    const taskDetail = Mock.mock({
        'id': 1123,
        'taskNumber': '201907050002',
        'taskName': '201907分享',
        'founder': '@cname',
        'foundTime': '2019-07-05 13:46',
        'personLiable': {'userId': 10, 'userName': '@cname'},
        'correlation': [],
        'implement': [],
        'completeTime': null,
        'taskPriority': 1,
        'taskStatus': 1,
        'task_content': [{'id': 2147, 'taskContent': '222', 'taskEnclosure': ['/file/task/1123/file/2410.docx']}],
        'pause': 0,
        'role': [1, 2]
    });
    const taskLog = Mock.mock({
        'list|5': [{
            'type': 1,
            'userName': '@cname',
            'content': '@csentence(50)',
            'opAt': '@datetime'
        }],
        'rowcount': 1
    });
    // API::各种任务
    app.post(prefix + 'found', (req, res) => {
        const code = 200;
        const msg = '';
        const data = {'res': 1};
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    // API::各种任务
    app.get(prefix + 'myfound', (req, res) => {
        const code = 200;
        const msg = '';
        const data = taskList;
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    // API::各种任务
    app.get(prefix + 'myown', (req, res) => {
        const code = 200;
        const msg = '';
        const data = taskList;
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    // API::各种任务
    app.get(prefix + 'myexe', (req, res) => {
        const code = 200;
        const msg = '';
        const data = taskList;
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    // API::各种任务
    app.get(prefix + 'aboutme', (req, res) => {
        const code = 200;
        const msg = '';
        const data = taskList;
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    // API::任务详情
    app.get(prefix + 'detail', (req, res) => {
        const code = 200;
        const msg = '';
        const data = taskDetail;
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
    // API::任务日志/轨迹
    app.get(prefix + 'tasklog', (req, res) => {
        const code = 200;
        const msg = '';
        const data = taskLog;
        const time = +(new Date);
        const result = {code, data, msg, time};
        return res.end(JSON.stringify(result));
    });
};
